/**
 * 
 */
package org.metaverse.h2;

import java.util.Date;

import org.metaverse.h2.cache.ValueCache;
import org.metaverse.warehouse.util.AbstractLazyCachedSenary;
import org.openrdf.model.Resource;
import org.openrdf.model.URI;
import org.openrdf.model.Value;
import org.openrdf.model.ValueFactory;

/**
 * @author vjache
 *
 */
public class LazySenary extends AbstractLazyCachedSenary {
	private static final long serialVersionUID = 2424723770782570961L;
	
	private static final int SUBJ_NUM = 0;
	private static final int PRED_NUM = SUBJ_NUM+1;
	private static final int OBJ_NUM = PRED_NUM+1;
	private static final int CTX_NUM = OBJ_NUM+1;
	private static final int USR_NUM = CTX_NUM+1;
	
	private final long[] _row;
	private final long _lat;
	private final ValueCache _nodeCache;

	/**
	 * 
	 */
	public LazySenary(long[] aRow,long aLat,ValueCache aNodeCache) {
		_row = aRow;
		_nodeCache = aNodeCache;
		_lat = aLat;
	}

	/* (non-Javadoc)
	 * @see org.metaverse.warehouse.util.AbstractLazyCachedSenary#readContext()
	 */
	@Override
	protected Resource readContext() {
		return _nodeCache.getValueById(_row[CTX_NUM]);
	}

	/* (non-Javadoc)
	 * @see org.metaverse.warehouse.util.AbstractLazyCachedSenary#readLastAssertTime()
	 */
	@Override
	protected Date readLastAssertTime() {
		return new Date(_lat);
	}

	/* (non-Javadoc)
	 * @see org.metaverse.warehouse.util.AbstractLazyCachedSenary#readObject()
	 */
	@Override
	protected Value readObject() {
		return _nodeCache.getValueById(_row[OBJ_NUM]);
	}

	/* (non-Javadoc)
	 * @see org.metaverse.warehouse.util.AbstractLazyCachedSenary#readPredicate()
	 */
	@Override
	protected URI readPredicate() {
		return _nodeCache.getValueById(_row[PRED_NUM]);
	}

	/* (non-Javadoc)
	 * @see org.metaverse.warehouse.util.AbstractLazyCachedSenary#readSubject()
	 */
	@Override
	protected Resource readSubject() {
		return _nodeCache.getValueById(_row[SUBJ_NUM]);
	}

	/* (non-Javadoc)
	 * @see org.metaverse.warehouse.util.AbstractLazyCachedSenary#readUser()
	 */
	@Override
	protected URI readUser() {
		return _nodeCache.getValueById(_row[USR_NUM]);
	}

	/* (non-Javadoc)
	 * @see org.metaverse.warehouse.util.AbstractLazySenary#getValueFactory()
	 */
	@Override
	protected ValueFactory getValueFactory() {
		return _nodeCache.getValueFactory();
	}

}
